-- bishop_skill
-- create by shuzy
-- 主教主动技能

return {
    apply = function(source, target, skillId, round, para, extra)
        assert(source.type == OBJECT_TYPE_BISHOP);
        local level = source:getSkillLevel(skillId);
        level = math.max(1, level);
        -- 威力
        local force = para[1] + para[2] * level;

        -- 1. 攻击方的魔力
        local magic = source:getMagic();

        -- 被对方百分比削弱
        local prop = PropM.combine(target, "weak_enemy", "magic");
        magic = PropM.apply(prop, magic);

        -- 被对方绝对值削弱
        prop = PropM.combine(target, "weak_enemy2", "magic");
        magic = PropM.apply(prop, magic);

        -- 4. 伤害/计算伤害时魔力+3
        local damage = math.modf(force * magic / 1000);

        -- 5. 魔法抗性
        prop = PropM.combine(target, "resist", "magic");
        -- 忽视抗性
        local p = PropM.combine(source, "ignore_resist", skillId);
        prop[3] = PropM.apply(p, prop[3]);
        p = PropM.combine(source, "ignore_resist", "magic");
        prop[3] = PropM.apply(p, prop[3]);

        damage = PropM.apply(prop, damage);

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 伤害
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 附加惩戒效果
        local effectRound = -1;
        extra = extra or {};
        local lastRound = extra.lastRound;

        if type(lastRound) == "number" then
            effectRound = round + lastRound + 1;
        elseif para[7] > 0 then
            effectRound = round + para[7] + 1;
        end

        prop = { para[4], para[5], para[6], effectRound, }
        local condition = {
            ["prop"] = prop,
            ["end_round"] = effectRound,
        };
        -- 附加状态
        CombatStatusM.applyStatus(target, para[3], condition);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), arr[3], tonumber(arr[4]), arr[5], tonumber(arr[6]), tonumber(arr[7] or -1), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para, extra)
        local bishop = source.bishop;
        if not bishop then
            return "";
        end

        if extra and extra == "bishop_active" then
            desc = BishopM.querySkill(skillId, "desc");
        end

        local level = bishop:getSkillLevel(skillId);
        level = math.max(1, level);
        -- 威力
        local base = para[1] + para[2] * level;

        -- 暂无加成
        local force = para[1] + para[2] * level;

        -- 2. 攻击方的魔力
        local magic = bishop:getMagic();

        -- 3. 伤害
        local damageForce = math.modf(force * magic / 1000);
        local damageBase = math.modf(base * magic / 1000)
        local damageAddon = damageForce - damageBase;
        if damageAddon == 0 then
            desc = string.gsub(desc, "{damage}", damageForce);
        else
            desc = string.gsub(desc, "{damage}", damageBase .. "(+" .. damageAddon .. ")");
        end

        local effectRound = para[7];
        desc = string.gsub(desc, "{round}", effectRound);

        return desc;
    end,
};
